﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using QuanLyTiemVang.DTO;

namespace QuanLyTiemVang.DAO
{
    class PhieuNoDAO
    {
        private static QUANLYTIEMVANGEntities dbContext = new QUANLYTIEMVANGEntities();

        public static List<PHIEUNO> GetAllPhieuNo()
        {
            return dbContext.PHIEUNOes.ToList();
        }
        public static void Insert(PHIEUNO pn)
        {
            dbContext.PHIEUNOes.Add(pn);
            dbContext.SaveChanges();
        }
        public static void Delete(PHIEUNO pn)
        {
            var query = dbContext.PHIEUNOes.Find(pn.MaPhieuNo);
            if (query != null)
            {
                dbContext.PHIEUNOes.Remove(query);
                dbContext.SaveChanges();
            }
        }
        public static int GetLastMaPhieuNo()
        {
            var query = (from d in dbContext.PHIEUNOes
                         select d.MaPhieuNo).ToList();

            if (query.Count == 0)
            {
                return 1;
            }

            return query.Max() + 1;
        }
    }
}
